var id = "";
function product_display(e) {
    id = e;
    var url = "goodsDetailProductDisplayServlet?product_id=" + e;
    $(function () {
        $.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function (res) {
                if (res.length==0){
                    return;
                }
                for (var i = 0; i < res.length; i++) {
                    document.getElementById("row_picture_img").setAttribute("src",res[i].picture);
                    document.getElementById("row_commodity_name").innerText = res[i].name;
                    document.getElementById("row_commodity_Price").innerText = res[i].price;
                }
            },
            error: function (res) {
                alert("所有商品图片调用失败！")
            }
        });
    })
}

//判断是否的登录
function goodsDetail_login() {
    var user = document.getElementById("top1_login").innerText;
    var top1 = document.getElementById("top1");
    var container_top = document.getElementById("container_top");
    if (user.trim().length == 0){
        document.getElementById("top1_login").innerText = "登录";
        document.getElementById("top2_gwc").innerText = "0";
        top1.style.width = "140px";
        container_top.style.width = "240px";
        container_top.style.marginLeft = "288px";
    }else if (user.trim().length != 0 && user != "登录"){
        document.getElementById("top1_login").setAttribute("href","#");
        top1.style.width = "195px";
        container_top.style.width = "300px";
        container_top.style.marginLeft = "234px";
    }
}
//加入购物车的点击事件
function shoppin() {
    // alert("1");
    var register =  document.getElementById("top1_login").getAttribute("name");
    // alert(register);
    if (register.trim().length==0){
        window.location.href = "/MyXiaomiShop/login.jsp";
    }else {
        var user_name = document.getElementById("top1_login").innerText;
        var consignee_id = id;
        var commodity_name = document.getElementById("row_commodity_name").innerText;
        var commodity_Price = document.getElementById("row_commodity_Price").innerText;
        window.location.href = "/MyXiaomiShop/ShoppingTrolleyServlet?user_name=" + user_name +"&consignee_id=" +consignee_id +"&commodity_name=" + commodity_name +"&commodity_Price=" + commodity_Price;
    }
}

//购物车的点击事件
function shopping_click() {
    var register =  document.getElementById("top2_a").getAttribute("name");
    // alert(register);
    if (register.trim().length==0){
        window.location.href = "/MyXiaomiShop/login.jsp";
    }else {
        window.location.href = "/MyXiaomiShop/cart.jsp";
    }
}

//搜索商品 并跳转到搜索页面
function search_product() {
    var search_count = 0;
    var product_name = document.getElementById("search_txt").value;
    if (product_name.trim().length == 0){
        box_table_add();
        return;
    }else {
        window.location.href = "/MyXiaomiShop/searchServlet?search_name="+product_name;
    }
}

//我的订单点击事件
function my_order() {
    var top1_login = document.getElementById("top1_login").innerText;
    if (top1_login == "登录"){
        window.location.href = "/MyXiaomiShop/login.jsp";
    }else {
        window.location.href = "/MyXiaomiShop/orderList.jsp";
    }
}